package com.etone.smartAudit.controller;

import com.etone.smartAudit.annotation.LoginAdmin;
import com.etone.smartAudit.domain.Admin;
import com.etone.smartAudit.dto.serviceExpert.ServiceExpertDTO;
import com.etone.smartAudit.service.ServiceExpertService;
import com.etone.smartAudit.vo.PagerVO;
import com.etone.smartAudit.vo.serviceExpert.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Collections;
import java.util.List;

/**
 * @author: 蒋学伟
 * @create: 2020-07-22 14:54:07
 * @Description
 */
@AllArgsConstructor
@RestController
@Api(tags = "服务专家管理", value = "ServiceExpertController")
public class ServiceExpertController {

    private ServiceExpertService serviceExpertService;

    @ApiOperation(value = "专家列表")
    @GetMapping("/serviceExperts")
    public PagerVO<ServiceExpertVO> list(
            @ApiParam(value = "专家名称") @RequestParam(required = false) String name,
            @ApiParam(value = "当前页") @RequestParam(required = false, defaultValue = "1") int page,
            @ApiParam(value = "每页显示数量") @RequestParam(required = false, defaultValue = "10") int pageSize
    ) {
        return serviceExpertService.list(name, page, pageSize);
    }

    @ApiOperation(value = "专家基本信息列表")
    @GetMapping("/serviceExperts/simple")
    public List<ServiceExpertBaseVO> listSimple(@LoginAdmin @ApiIgnore Admin admin) {
        return serviceExpertService.listSimple();
    }

    @ApiOperation(value = "专家详情")
    @GetMapping("/serviceExperts/{id}")
    public ServiceExpertDetailVO detail(
            @ApiParam("专家id") @PathVariable Integer id
    ) {
        return serviceExpertService.detail(id);
    }

    @ApiOperation(value = "专家支撑项目列表")
    @GetMapping("/serviceExperts/{id}/items")
    public PagerVO<ServiceExpertItem> listServiceExpertItem(
            @ApiParam("专家id") @PathVariable Integer id,
            @ApiParam(value = "当前页") @RequestParam(required = false, defaultValue = "1") int page,
            @ApiParam(value = "每页显示数量") @RequestParam(required = false, defaultValue = "10") int pageSize
    ) {
        return serviceExpertService.listServiceExpertItem(id, page, pageSize);
    }

    @ApiOperation(value = "编辑专家")
    @PutMapping("/serviceExperts/{id}")
    public void edit(
            @ApiParam("专家id") @PathVariable Integer id,
            @ApiParam(value = "专家详情表单") @RequestBody @Validated ServiceExpertDTO serviceExpertDTO
    ) {
        serviceExpertService.edit(id, serviceExpertDTO);
    }

    @ApiOperation(value = "专家人员信息列表")
    @GetMapping("/serviceExperts/{id}/memberInfos")
    public PagerVO<ServiceExpertMemberVO> memberInfos(
            @ApiParam("专家id") @PathVariable Integer id,
            @ApiParam(value = "当前页") @RequestParam(required = false, defaultValue = "1") int page,
            @ApiParam(value = "每页显示数量") @RequestParam(required = false, defaultValue = "10") int pageSize
    ) {
        return serviceExpertService.memberInfos(id, page, pageSize);
    }
}
